<template>
	<view class="pad-0-16r">
		<!-- 只用于暂时，选择后不用更新到数据库 -->
		<view class="campus" @click="showChangeBranch" v-if="dataSource[index]">
			<view class="start-center">
				<image v-if="dataSource[index].icon" class="img-campus" :src="hostApi+dataSource[index].icon"></image>
				<image v-else class="img-campus" src="/static/images/campus/campuslogo.png"></image>
				<view class="campus-name">{{dataSource[index].name}}</view>
			</view>
			<view>
				选择院区
				<u-icon name="arrow-right" class="mar-0-5"></u-icon>
			</view>
		</view>
		<ChangeSelect tabindex="0" :show="selectShow" :current="index" title="切换院区" :list="dataSource"
			@updateCurrent="updateCurrent" @close="close" />
	</view>
</template>

<script>
	import {
		selectCampus
	} from '../../api/campus';
	import {
		mapGetters,
		mapActions
	} from 'vuex';
	export default {
		name: "checkBranch",
		props: {
			campusCode: String
		},
		computed: {
			...mapGetters([
				'hospitalInfo', 'userInfo', "hostApi"
			])
		},
		data() {
			return {
				selectShow: false,
				dataSource: [],
				index: 0,
			};
		},
		mounted() {
			this.init()
		},
		methods: {
			...mapActions(['getHospitalInfo', "getBindInfo"]),
			async init() {
				if (this.hospitalInfo == '') {
					const res = await selectCampus({})
					this.dataSource = res;
					this.getHospitalInfo(res);
				} else {
					this.dataSource = this.hospitalInfo
				}
				console.log(this.campusCode)
				for (let i = 0; i < this.dataSource.length; i++) {
					if (this.dataSource[i].code == this.campusCode) {
						this.index = i;
						break
					}
				}
			},
			showChangeBranch() {
				this.selectShow = true
			},
			updateCurrent(v) {
				this.index = v;
				this.updatePatientCardCampus(v)
				this.selectShow = false;

			},
			close() {
				this.selectShow = false;
			},
			updatePatientCardCampus(v) {
				this.$emit('updateCampus', this.dataSource[v].code)
			},

		}
	}
</script>

<style scoped>
	.campus {
		padding: 0 16rpx;
		height: 50px;
		line-height: 50px;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.branch {
		justify-content: space-between;
		height: 108upx;
		line-height: 108upx;
		padding: 0 24upx;
		background-color: #FFF;
		border-bottom: 1px solid rgba(0, 0, 0, 0.12);
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28upx;
		color: rgba(0, 0, 0, 0.5);
	}

	.img-campus {
		width: 20px;
		height: 20px;
		border-radius: 16rpx;
		margin-right: 10rpx;
	}

	.campus-name {
		height: 15px;
		font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
		font-weight: 400;
		font-size: 15px;
		color: #333333;
		line-height: 15px;
		text-align: left;
		font-style: normal;
		text-transform: none;
	}
</style>